package com.woniuxy.java106crm.controller;

import com.woniuxy.java106crm.annotation.RequireMethod;
import com.woniuxy.java106crm.entity.Customer;
import com.woniuxy.java106crm.entity.Lost;
import com.woniuxy.java106crm.request.ResPage;
import com.woniuxy.java106crm.request.ResponseResult;
import com.woniuxy.java106crm.service.LostService;
import com.woniuxy.java106crm.service.SureLostService;
import com.woniuxy.java106crm.vo.ServiceTypeCountVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Api(tags = "客户流失管理模块API文档")
@Slf4j
@RestController
@RequestMapping("/lost")
public class LostController {
    @Resource
    private LostService lostService;

    @Resource
    private SureLostService sureLostService;

    @PreAuthorize("hasAuthority('客户流失管理')")
    @RequireMethod("获取所有流失客户信息")
    @GetMapping("/getDate/{page}/{size}")
    public ResponseResult<ResPage<List<Lost>>> getDate(
            @PathVariable("page")Integer page, @PathVariable("size") Integer size){
        ResPage<List<Lost>> resPage = lostService.findAllLostPage(page,size);
        return new ResponseResult<>(ResponseResult.OK,resPage);
    }

    @PreAuthorize("hasAuthority('客户流失管理')")
    @RequireMethod("查询流失客户信息")
    @GetMapping("/queryCondition/{page}/{size}")
    public ResponseResult<ResPage<List<Lost>>> queryCondition(
            @PathVariable("page")Integer page, @PathVariable("size") Integer size, Lost lost){
        ResPage<List<Lost>> resPage = lostService.queryCondition(page,size,lost);
        return new ResponseResult<>(ResponseResult.OK,resPage);
    }

    @PreAuthorize("hasAuthority('客户流失管理')")
    @RequireMethod("暂缓客户流失")
    @PostMapping("/slow")
    public ResponseResult<Boolean> slow(@RequestBody Lost lost){
        lostService.slow(lost);
        return new ResponseResult<>(ResponseResult.OK,true);
    }

    @PreAuthorize("hasAuthority('客户流失管理')")
    @RequireMethod("确认客户流失")
    @PostMapping("/sure")
    public ResponseResult<Boolean> sure(@RequestBody Lost lost){
        return new ResponseResult<>(ResponseResult.OK,lostService.sure(lost));
    }

    @PreAuthorize("hasAuthority('客户流失分析')")
    @RequireMethod("查看流失客户分析")
    @GetMapping("/lostCustomerAnalyze")
    public ResponseResult<List<ServiceTypeCountVo>> lostCustomerAnalyze(){
        return new ResponseResult<>(ResponseResult.OK,sureLostService.lostCustomerAnalyze());
    }
}
